package cn.tude.egcar1.controller;

import cn.tude.egcar1.base.response.JsonResult;
import cn.tude.egcar1.mapper.VehicleMapper;
import cn.tude.egcar1.pojo.dto.VehicleAddParam;
import cn.tude.egcar1.pojo.entity.Vehicle;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/v1/vehicle")
@Tag(name = "车辆管理模块")
@Slf4j
public class VehicleController {
    @Autowired
    VehicleMapper vehicleMapper;
    @PostMapping("add")
    public JsonResult add(@RequestBody VehicleAddParam vehicleAddParam){
        log.debug("vehicleAddParam="+vehicleAddParam);
        Vehicle vehicle = new Vehicle();
        BeanUtils.copyProperties(vehicleAddParam,vehicle);
        vehicle.setCreate_time(new Date());
        vehicle.setUpdate_time(new Date());
        log.debug("vehicle="+vehicle);
        vehicleMapper.insertVehicle(vehicle);
        return JsonResult.ok();

    }
}
